Praxis KJV 작업일지

022726

원본 = KJV Bible_original.txt
새이름 = PKJV.txt
ReformatVerse.py = 혼합된 절을 잘 분리해서 정돈해줌
ReformatChapter.py = 혼합된 절을 포함해서 장 표시를 삽입시켜 줌. 결과 = PKJV_Final_Ch.md 와 PKJV_Final_Ch.txt

아래 파일을 사용 완료

import re
import os

def kjv_expert_formatter(input_file, md_output, txt_output):
    # KJV 전용 도서 명칭 리스트 (기존과 동일)
    kjv_book_titles = [
        "The Old Testament of the King James Version of the Bible",
        "The First Book of Moses: Called Genesis",
        "The Second Book of Moses: Called Exodus",
        # ... (이전 리스트와 동일하게 유지)
        "The Revelation of Saint John the Divine"
    ]

    if not os.path.exists(input_file):
        print(f"❌ 원본 파일을 찾을 수 없습니다: {input_file}")
        return

    with open(input_file, 'r', encoding='utf-8') as f:
        content = f.read()

    # 1. 전처리: 문장 파편화 제거 (Unwrap)
    content = re.sub(r'\s+', ' ', content)

    # 2. 절 번호(장:절) 패턴 앞에 강제 줄바꿈 삽입
    content = re.sub(r'(\d+:\d+)', r'\n\1', content)

    # 3. KJV 제목 마킹
    for title in kjv_book_titles:
        content = content.replace(title, f"\n[KJV_TITLE]{title}[/KJV_TITLE]\n")

    lines = content.split('\n')
    md_final = []
    txt_final = []
    
    current_chapter = None  # 현재 추적 중인 장 번호

    for line in lines:
        line = line.strip()
        if not line: continue

        # [KJV 제목 처리]
        if "[KJV_TITLE]" in line:
            clean_title = line.replace("[KJV_TITLE]", "").replace("[/KJV_TITLE]", "")
            md_final.append(f"\n# {clean_title}\n")
            txt_final.append(f"\n[{clean_title}]\n")
            current_chapter = None # 책이 바뀌면 장 번호 초기화
        
        # [성경 본문 및 장 구분 처리]
        elif re.match(r'^(\d+):(\d+)', line):
            match = re.match(r'^(\d+):(\d+)', line)
            chapter_num = match.group(1) # 장 번호 추출
            
            # 장 번호가 바뀌었는지 확인 (예: 1에서 2로)
            if chapter_num != current_chapter:
                current_chapter = chapter_num
                # 마크다운에는 H2 헤더로 장 표시
                md_final.append(f"\n## {current_chapter} Chapter\n")
                # 텍스트 파일에는 구분선과 함께 장 표시
                txt_final.append(f"\n--- {current_chapter} Chapter ---\n")

            # 본문 가공
            formatted_line = re.sub(r'^(\d+:\d+)\s*', r'\1 ', line)
            md_final.append(formatted_line)
            txt_final.append(formatted_line)

    # 4. 결과 저장
    with open(md_output, 'w', encoding='utf-8') as f:
        f.write("\n\n".join(md_final))
    
    with open(txt_output, 'w', encoding='utf-8') as f:
        f.write("\n".join(txt_final))

    print(f"✅ 장(Chapter) 구분 포함 정밀 편집 완료!")

if __name__ == "__main__":
    BASE_PATH = r"D:\Kee_Drive\SynologyDrive\KeeDian\03_Knowledge\00_Praxis Bible\PraxisKJV"
    IN_FILE = os.path.join(BASE_PATH, "PKJV.txt")
    MD_OUT = os.path.join(BASE_PATH, "PKJV_Final_Ch.md")
    TXT_OUT = os.path.join(BASE_PATH, "PKJV_Final_Ch.txt")
    kjv_expert_formatter(IN_FILE, MD_OUT, TXT_OUT)

🛠 통합된 핵심 기능 분석

📝 결과물 구조 예시

이 코드를 실행하면 내부적으로 다음과 같은 흐름으로 데이터가 정렬됩니다:

  1. # The First Book of Moses: Called Genesis (책 제목 감지)

  2. ## 1 Chapter (첫 장 시작 감지)

  3. 1:1 In the beginning... (절 단위 정렬)

  4. ...

  5. 1:31 And God saw... (1장의 마지막 절)

  6. ## 2 Chapter (숫자 변화 감지 후 자동 삽입)

  7. 2:1 Thus the heavens... (2장의 시작)